home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / MPW etc / MPW-GM / MPW / Examples / CExamples / TestPerf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-12-03  |  4.1 KB  |  240 lines  |  [TEXT/MPS ]

  1. /*
  2.  * File TestPerf.c
  3.  *
  4.  * Copyright Apple Computer, Inc. 1987, 1995
  5.  * All rights reserved.
  6.  *
  7.  *    This tool demonstrates the use of the performance tools in C.
  8.  */
  9.  
  10. /* 
  11.     #define PERFORMANCE to turn on the measuring tools.
  12.     #undef PERFORMANCE to turn off the measuring tools.
  13. */
  14. #define    PERFORMANCE
  15.  
  16. #ifdef PERFORMANCE
  17. #include    <Perf.h>
  18. #endif PERFORMANCE
  19.  
  20. #include    <QuickDraw.h>
  21. #include    <stdio.h>
  22.  
  23.  
  24. void    W500A();
  25. void    W100();
  26. void    W1500();
  27. void    Waste();
  28. void    W500B();
  29. void    ROMW500A();
  30. void    ROMW100();
  31. void    ROMW1500();
  32. void    ROMWaste();
  33. void    ROMW500B();
  34.     
  35. int main (void)
  36. {
  37.     short            repeats;                /* a looping variable */
  38. #ifdef PERFORMANCE
  39.     TP2PerfGlobals    ThePGlobals = nil;        /* performance globals */
  40.  
  41.     /* Initialize the performance globals */
  42.     if (!InitPerf(&ThePGlobals,
  43.             4,                    /* ms */
  44.             8,                    /* bytes */
  45.             true,                /* measure ROM code */
  46.             true,                 /* measure application code */
  47.             (StringPtr)"\pCODE",/* segments to measure */
  48.             0,                    /* Let the performance tools calculate the ROM id */
  49.             (StringPtr)"\p",    /* Let the performance tools find the ROM name */
  50.             false,                /* don't measure RAM */
  51.             0,                    /* low RAM address */
  52.             0xFFFFF,            /* high RAM address */
  53.             16                    /* RAM bucket size */
  54.         )) {
  55.             fprintf(stderr, "Errors during initperf.\n");
  56.                 return(1);
  57.     };
  58.     (void)PerfControl(ThePGlobals, true);    /* turn on measurements */
  59. #endif PERFORMANCE
  60.  
  61.     for (repeats = 5; repeats; repeats--) {
  62.         /* waste some time in user code/MUL4 */
  63.         Waste();
  64.         W100();
  65.         W500A();
  66.         W500B();
  67.         W1500();
  68.         /* waste some time in ROM calls: */
  69.         ROMWaste();
  70.         ROMW100();
  71.         ROMW500A();
  72.         ROMW500B();
  73.         ROMW1500();
  74.     };
  75. #ifdef PERFORMANCE
  76.     (void)PerfControl(ThePGlobals, false);    /* turn off measurements */
  77.  
  78.     /* Write the performance raw data into a file */
  79.     if (PerfDump(ThePGlobals, (StringPtr)"\pPerform.out", true, 80) ) 
  80.         fprintf(stderr, "Errors during dump.\n");
  81.  
  82.     TermPerf(ThePGlobals);    /* clean up */
  83. #endif PERFORMANCE
  84.     return(0);
  85. }
  86.  
  87.  
  88. #pragma    segment    Seg1
  89.  
  90. void W500A(void)
  91. {
  92.     short    i;
  93.     int        junk;
  94.     int        junk1;
  95.     int        junk2;
  96.  
  97.     for (i = 1; i <= 500; i++) {
  98.         junk = 1;
  99.         junk1 = junk * 5;
  100.         junk2 = (junk + junk1) * 5;
  101.     };
  102. }; 
  103.         
  104. void W100(void)
  105. {
  106.     short    i;
  107.     int        junk;
  108.     int        junk1;
  109.     int        junk2;
  110.  
  111.     for (i = 1; i <= 100; i++) {
  112.         junk = 1;
  113.         junk1 = junk * 5;
  114.         junk2 = (junk + junk1) * 5;
  115.     };
  116. }; 
  117.  
  118. void W1500(void)
  119. {
  120.     short    i;
  121.     int        junk;
  122.     int        junk1;
  123.     int        junk2;
  124.  
  125.     for (i = 1; i <= 1500; i++) {
  126.         junk = 1;
  127.         junk1 = junk * 5;
  128.         junk2 = (junk + junk1) * 5;
  129.     };
  130. }; 
  131.  
  132. #pragma    segment    SEG2
  133.  
  134. void Waste(void)
  135. {
  136.     short    i;
  137.     int        junk;
  138.     int        junk1;
  139.     int        junk2;
  140.  
  141.     for (i = 1; i <= 1; i++) {
  142.         junk = 1;
  143.         junk1 = junk * 5;
  144.         junk2 = (junk + junk1) * 5;
  145.     };
  146. }; 
  147.  
  148. void W500B(void)
  149. {
  150.     short    i;
  151.     int        junk;
  152.     int        junk1;
  153.     int        junk2;
  154.  
  155.     for (i = 1; i <= 500; i++) {
  156.         junk = 1;
  157.         junk1 = junk * 5;
  158.         junk2 = (junk + junk1) * 5;
  159.     };
  160. }; 
  161.         
  162. #pragma    segment    ROMSEG1
  163.  
  164. void ROMW500A(void)
  165. {
  166.     short    i;
  167.     Rect    junk;
  168.     Rect    junk1;
  169.     Rect    junk2;
  170.     Boolean    dontCare;
  171.         
  172.     for (i = 1; i <= 500; i++) {
  173.         SetRect(&junk, 100, 200, 300, 400);
  174.         SetRect(&junk1, 200, 300, 400, 500);
  175.         dontCare = SectRect(&junk, &junk1, &junk2);
  176.     };
  177. };
  178.         
  179. void ROMW100(void)
  180. {
  181.     short    i;
  182.     Rect    junk;
  183.     Rect    junk1;
  184.     Rect    junk2;
  185.     Boolean    dontCare;
  186.         
  187.     for (i = 1; i <= 100; i++) {
  188.         SetRect(&junk, 100, 200, 300, 400);
  189.         SetRect(&junk1, 200, 300, 400, 500);
  190.         dontCare = SectRect(&junk, &junk1, &junk2);
  191.     };
  192. };
  193.         
  194. void ROMW1500(void)
  195. {
  196.     short    i;
  197.     Rect    junk;
  198.     Rect    junk1;
  199.     Rect    junk2;
  200.     Boolean    dontCare;
  201.         
  202.     for (i = 1; i <= 1500; i++) {
  203.         SetRect(&junk, 100, 200, 300, 400);
  204.         SetRect(&junk1, 200, 300, 400, 500);
  205.         dontCare = SectRect(&junk, &junk1, &junk2);
  206.     };
  207. };
  208.         
  209. #pragma    segment    ROMSEG2
  210.  
  211. void ROMWaste(void)
  212. {
  213.     short    i;
  214.     Rect    junk;
  215.     Rect    junk1;
  216.     Rect    junk2;
  217.     Boolean    dontCare;
  218.         
  219.     for (i = 1; i <= 1; i++) {
  220.         SetRect(&junk, 100, 200, 300, 400);
  221.         SetRect(&junk1, 200, 300, 400, 500);
  222.         dontCare = SectRect(&junk, &junk1, &junk2);
  223.     };
  224. };
  225.         
  226. void ROMW500B(void)
  227. {
  228.     short    i;
  229.     Rect    junk;
  230.     Rect    junk1;
  231.     Rect    junk2;
  232.     Boolean    dontCare;
  233.         
  234.     for (i = 1; i <= 500; i++) {
  235.         SetRect(&junk, 100, 200, 300, 400);
  236.         SetRect(&junk1, 200, 300, 400, 500);
  237.         dontCare = SectRect(&junk, &junk1, &junk2);
  238.     };
  239. };
  240.